/*
* berton
*/
package com.pitop.material.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import com.pitop.material.api.MaterialCategoryFeignApi;
import com.pitop.core.exceptions.MaterialCategoryException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.material.entity.MaterialCategory;


/**
 * 供应类型
 * @author berton
 */
@Service("materialCategorySVImpl")
@Slf4j
public class MaterialCategorySVImpl {

    @Autowired
    private MaterialCategoryFeignApi materialCategoryFeignApi;

    /**
     * 加载一个对象MaterialCategory
     * @param id * @param code 编码
     * @return MaterialCategory
     */
    public MaterialCategory load(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new MaterialCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialCategoryFeignApi.load(id,code);
    }
    /**
     * 加载一个对象MaterialCategory 通过id
     * @param id 
     * @return MaterialCategory
     */
    public MaterialCategory loadById(java.lang.Long id) {
        if(id==null){
            throw new MaterialCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialCategoryFeignApi.loadById(id);
    }

    /**
     * 加载一个对象MaterialCategory 通过code
     * @param code 编码
     * @return MaterialCategory
     */
    public MaterialCategory loadByCode(java.lang.String code) {
        if(code==null){
            throw new MaterialCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialCategoryFeignApi.loadByCode(code);
    }


    /**
     * 删除对象MaterialCategory
     * @param id * @param code 编码
     * @return MaterialCategory
     */
    
    public void delete(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new MaterialCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        materialCategoryFeignApi.delete(id,code);
    }



    /**
     * 查询MaterialCategory分页
     *
     * @param materialCategory  对象
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<MaterialCategory>
     */
    public List<MaterialCategory> list(MaterialCategory materialCategory, int curPage,int pageSize) {
        return materialCategoryFeignApi.list(materialCategory, curPage,pageSize);
    }

    /**
     * 查询MaterialCategory分页
     *
     * @param id  * @param code  编码
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<MaterialCategory>
     */
    public List<MaterialCategory> list(java.lang.Long id,java.lang.String code,int curPage, int pageSize) {
        if (curPage < 0) {
           curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        MaterialCategory materialCategory=new MaterialCategory();
        materialCategory.setId(id);
        materialCategory.setCode(code);

        return materialCategoryFeignApi.list(materialCategory,curPage,pageSize);
    }


    public int count(java.lang.Long id,java.lang.String code) {
        return materialCategoryFeignApi.count(id,code);
    }


    public int count(MaterialCategory materialCategory) {
        return materialCategoryFeignApi.count(materialCategory);
    }


    /**
     * 保存
     *
     * @param materialCategory 实体
     * @throws BaseException
     */
    public void save(MaterialCategory materialCategory) {
        if(materialCategory==null){ throw new MaterialCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        materialCategoryFeignApi.build(materialCategory);
    }

    /**
     * 更新
     *
     * @param materialCategory 实体
     * @throws BaseException
     */
    public void modify(MaterialCategory materialCategory) {
        if(materialCategory==null){ throw new MaterialCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        materialCategoryFeignApi.modify(materialCategory);
    }

}
